home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS04.ADF / image.ed / changecolor.c < prev    next >
C/C++ Source or Header  |  1985-10-26  |  10KB  |  277 lines

  1.  
  2.  
  3. /************* changecolor3.c ************/
  4. #include "intuall.h"
  5. #include "imageedit.h"
  6. #define SLIDERGADGETS 0x64      /* later move into imageedit.h */
  7.  
  8. /* this file contains the information for the requester that allows you
  9.  * to change the colors that are being used for the image editor. */ 
  10.  
  11. /* there are 3 porportional gadgets, one for the red, one for green and
  12.  * one for blue
  13.  *
  14.  * Each points to the same image data for rendering the gadget
  15.  */
  16.  
  17. #define CGW 18
  18. #define CGH 12
  19. extern SHORT palette[];
  20. extern SHORT depth;
  21. struct Gadget ncp[33];
  22. struct Image cri[33];
  23.  
  24. struct Requester newcolorrequest;
  25.  
  26. SHORT wc[] = { 0,   0,                  /* this describes a box to draw */
  27.                80,  0,
  28.                80,  10,
  29.                0,   10,
  30.                0,   1,  
  31.                79,  1,  
  32.                79,  9,
  33.                1,   9,
  34.                1,   1   };              /* the line is double-width */
  35.  
  36. struct Border whichcolor = {
  37.         210, 2, 0, 1, JAM1, 9, &wc[0], NULL };
  38.  
  39.         /* initial offset position from 0,0 within requester x,y */
  40.         /* then drawing pens for rendering, and draw mode */
  41.         /* how many pairs of points defined, and where */
  42.         /* and is there a nextborder?  */
  43.  
  44.  
  45.  
  46. extern struct TextAttr TestFont;
  47.  
  48. struct IntuiText ncrt[] = {     /* ncrt stands for new color requester text */
  49.  
  50.         /* requester IntuiText for this color requester */
  51.  
  52.                 { 0,1,JAM1, 5, 1, &TestFont, (UBYTE *)"Select A Color:",
  53.                         &ncrt[1], }
  54.                 { 0,1,JAM1, 5, 15, &TestFont, (UBYTE *)"R:",
  55.                         &ncrt[2], }
  56.                 { 0,1,JAM1, 5, 28, &TestFont, (UBYTE *)"G:",
  57.                         &ncrt[3], }
  58.                 { 0,1,JAM1, 5, 41, &TestFont, (UBYTE *)"B:",
  59.                         &ncrt[4], }
  60.                 { 0,1,JAM1, 5, 65, &TestFont, (UBYTE *)"Move Sliders To Change It",
  61.                         &ncrt[5], }
  62.                 { 0,1,JAM1, 5, 78, &TestFont, (UBYTE *)"Click OK To Exit",
  63.                         &ncrt[6], }             
  64.                 { 0,1,JAM1, 5, 53, &TestFont, NULL,
  65.                         NULL,     }
  66.  
  67.         /* ncrt[6].IntuiText is used to identify the requester */
  68.  
  69.         /* gadget IntuiText for this color requester */
  70.          
  71.                 { 1,0,JAM2, 1, 0, &TestFont, (UBYTE *)"OK",
  72.                         NULL }  
  73.                 };
  74.  
  75.  
  76. UWORD horizslider[] = {
  77.                 0xc000,         /* first plane of image */
  78.                 0xf000,
  79.                 0xfc00,
  80.                 0xff00,
  81.                 0xfc00,
  82.                 0xf000,
  83.                 0xc000,
  84.                 
  85.                 0x0000,         /* second plane of image */
  86.                 0x3000,
  87.                 0x3000,
  88.                 0x3c00,
  89.                 0x3000,
  90.                 0x3000,
  91.                 0x0000 };       /* forms a right-facing arrow pointer */
  92.  
  93. struct Image sliderimage1[] = {
  94.                 {0,0,8,7,1,&horizslider[0],0x1,0,}
  95.                 {0,0,8,7,1,&horizslider[0],0x1,0,}
  96.                 {0,0,8,7,1,&horizslider[0],0x1,0 }    };
  97. struct Image sliderimage2[] = {
  98.                 {0,0,8,7,1,&horizslider[0],0x2,0,}
  99.                 {0,0,8,7,1,&horizslider[0],0x2,0,}
  100.                 {0,0,8,7,1,&horizslider[0],0x2,0 }    };
  101.  
  102. struct PropInfo myslider[3] = {         /* one for red,green,blue */
  103.                 {FREEHORIZ,    /* let it move freely in horizontal direction */
  104.                 0,0,          /* initial values of horizontal, vert. pot    */
  105.                 0x3fff,       /* HorizBody ... not using autoknob so this
  106.                                * may not be necessary to set to other than 0 */
  107.                 0,            /* VertBody */
  108.                 0,0,0,0,0,0,}           /* intuition's variables */
  109.                 {FREEHORIZ,    
  110.                 0,0,          
  111.                 0x3fff,      
  112.                             
  113.                 0,         
  114.                 0,0,0,0,0,0,}  
  115.                 {FREEHORIZ,   
  116.                 0,0,         
  117.                 0x0,        /* was 3fff, how far to move it when hit boxend */
  118.                            
  119.                 0,        
  120.                 0,0,0,0,0,0} }; 
  121. /* left edge, top edge, width, height, depth, predrawn image, ppick, pponoff */
  122. /*  
  123. struct Image sliderimage1 = {
  124.                 0,0,                    
  125.                 8,7,1,          
  126.                 &horizslider[0],
  127.                 0x2,    
  128.                 
  129.                 0 };
  130.  
  131. struct Image sliderimage2 = {
  132.                 0,0,                    
  133.                 8,7,2,          
  134.                 &horizslider[0],
  135.                 0x2,    
  136.                 
  137.                 0 };
  138.  
  139. */
  140. struct Gadget colorgadget[3] = {        /* here is the gadgetset for changing
  141.                                          * red, green and blue components of
  142.                                          * a currently selected color blot.
  143.                                          * Links together the other predefined
  144.                                          * information.
  145.                                          */
  146.                 { &colorgadget[1],      /* next gadget in this list */
  147.                   20,13,                /* left edge, top edge of hitbox */
  148.                   170,11,               /* width and height of hitbox */
  149.                   GADGIMAGE | GADGHIMAGE,/* flags */
  150.                   RELVERIFY |GADGIMMEDIATE,     /* activation flags */
  151.                   PROPGADGET | REQGADGET,   /* this is a proportional gadget */
  152.                   &sliderimage1[0],     /* render normally with this image */
  153.                   &sliderimage2[0],     /* render highlighted with this one */
  154.                   NULL,                 /* no text for this prop gadget */      
  155.                   0x06,                 /* mutual exclude */ 
  156.                   &myslider[0],         /* special info = define of prop */
  157.                   SLIDERGADGETS+0,      /* this gadget's identifier for me */
  158.                   NULL, }               /* no user data on this one */
  159.                 { &colorgadget[2],      
  160.                   20,26,        
  161.                   170,11,
  162.                   GADGIMAGE | GADGHIMAGE,/* flags */
  163.                   RELVERIFY | GADGIMMEDIATE,    
  164.                   PROPGADGET | REQGADGET,
  165.                   &sliderimage1[1],
  166.                   &sliderimage2[1],
  167.                   NULL,         
  168.                   0x05,
  169.                   &myslider[1],
  170.                   SLIDERGADGETS+1,      
  171.                   NULL, }
  172.                 { &ncp[0],      
  173.                   20,39,        
  174.                   170,11,
  175.                   GADGIMAGE | GADGHIMAGE,/* flags */
  176.                   RELVERIFY | GADGIMMEDIATE,    
  177.                   PROPGADGET | REQGADGET,
  178.                   &sliderimage1[2],
  179.                   &sliderimage2[2],
  180.                   NULL,         
  181.                   0x03,
  182.                   &myslider[2],
  183.                   SLIDERGADGETS+2,      
  184.                   NULL }   };
  185.  
  186.  
  187. /* the OK gadget lets people decide accept the colors they have */
  188. /* chosen.  Should also install a default colors gadget! */ 
  189.  
  190. struct Gadget ColorOKGadget = {
  191.         &colorgadget[0]                 /* address of next gadget */
  192.         180,78,20,9,                    /* left,top,width,height of hitbox */
  193.         GADGHCOMP,                      /* flags */
  194.         RELVERIFY | GADGIMMEDIATE | ENDGADGET,  
  195.                                         /* tell me only when he releases the
  196.                                          * mouse button and if over the
  197.                                          * gadget at that time */       
  198.         REQGADGET | BOOLGADGET, /* is a requestor, string */
  199.         NULL,                           /* BORDER descriptor */
  200.         NULL,                           /* SELECT descriptor */
  201.         &ncrt[7],                       /* OK */
  202.         0,                              /* mutual exclusion (could use) */
  203.         NULL,                           /* special info */
  204.         255,                            /* gadget identifier, user */
  205.         NULL };                         /* user data pointer */
  206.  
  207.  
  208. InitColorRequest()
  209. {
  210.         InitRequester(&newcolorrequest);
  211.         newcolorrequest.LeftEdge = 20;
  212.         newcolorrequest.TopEdge = 20;
  213.         newcolorrequest.Width = 320;
  214.         newcolorrequest.Height = 90;
  215.         newcolorrequest.ReqGadget = &ColorOKGadget;
  216.         newcolorrequest.ReqText = &ncrt[0];   
  217.         newcolorrequest.BackFill = 1;
  218.         newcolorrequest.ReqBorder = &whichcolor;
  219.  
  220.         return(0);
  221. }
  222.  
  223.  
  224. InitNewColorText()
  225. {  InitPaletteGadgets(depth);
  226.    return(0); }
  227.  
  228. InitPaletteGadgets(depth)
  229. SHORT depth;
  230. {
  231.         SHORT n;
  232.         for(n=0; n<(palette[depth-1]+1); n++)   
  233.         {
  234.         ncp[n].NextGadget = &ncp[n+1];
  235.         ncp[n].LeftEdge = 210 + (CGW+2) * (n % 4);
  236.         ncp[n].TopEdge = 14 + (CGH+2) * (n/4);          
  237.         ncp[n].Width = CGW;
  238.         ncp[n].Height = CGH;
  239.         ncp[n].Flags = GADGIMAGE | GADGHBOX;
  240.         ncp[n].Activation = RELVERIFY | GADGIMMEDIATE;
  241.         ncp[n].GadgetType = BOOLGADGET | REQGADGET;
  242.         ncp[n].GadgetRender = &cri[n];
  243.         ncp[n].SelectRender = NULL;
  244.         ncp[n].GadgetText = NULL;       
  245.         ncp[n].MutualExclude = 0;
  246.         ncp[n].SpecialInfo = NULL;
  247.         ncp[n].GadgetID = COLORGADGETS + n;
  248.         ncp[n].UserData = NULL;
  249.  
  250.         cri[n].LeftEdge = 1;
  251.         cri[n].TopEdge = 1;
  252.         cri[n].Width = CGW-2;
  253.         cri[n].Height = CGH-2;
  254.         cri[n].Depth = depth;
  255.         cri[n].ImageData = NULL;
  256.         cri[n].PlanePick = 0;
  257.         cri[n].PlaneOnOff = n;
  258.         } 
  259.         /* this gadget will be used to represent which color was selected,
  260.          * rather than fooling around with the various toggle-select flags
  261.          * for everybody and so on, simply change the gadget render for this
  262.          * last gadget on selecting anybody else in the color palette, the
  263.          * start a RefreshGadget with this last object in the chain.
  264.          */
  265.  
  266.         ncp[palette[depth-1]].LeftEdge = 211;
  267.         ncp[palette[depth-1]].TopEdge = 3;
  268.         ncp[palette[depth-1]].Width = 78;
  269.         ncp[palette[depth-1]].Height = 8;
  270.         cri[palette[depth-1]].Width = 76;            
  271.         cri[palette[depth-1]].Height = 8;            
  272.         ncp[palette[depth-1]].NextGadget = NULL;
  273.         return(0);
  274.  
  275.  
  276.